using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Domain.Entities;

namespace JGSY.CMS.LowCode.Platform.Domain.Interfaces
{
    /// <summary>
    /// 文章仓储接口
    /// 提供文章数据访问操作，支持文章管理和分类检索
    /// </summary>
    public interface IArticleRepository
    {
        /// <summary>
        /// 获取所有文章记录
        /// </summary>
        /// <returns>文章实体列表</returns>
        Task<IEnumerable<Article>> GetAllAsync();
        
        /// <summary>
        /// 根据ID获取文章记录
        /// </summary>
        /// <param name="id">文章标识符</param>
        /// <returns>文章实体，如果未找到则返回null</returns>
        Task<Article?> GetByIdAsync(long id);

        /// <summary>
        /// 根据别名获取文章记录
        /// </summary>
        /// <param name="slug">文章别名</param>
        /// <returns>文章实体，如果未找到则返回null</returns>
        Task<Article?> GetBySlugAsync(string slug);

        /// <summary>
        /// 根据分类获取文章列表
        /// </summary>
        /// <param name="categoryId">分类ID</param>
        /// <returns>文章列表</returns>
        Task<IEnumerable<Article>> GetByCategoryAsync(long categoryId);

        /// <summary>
        /// 获取置顶文章
        /// </summary>
        /// <param name="count">数量限制</param>
        /// <returns>置顶文章列表</returns>
        Task<IEnumerable<Article>> GetStickyArticlesAsync(int count = 10);

        /// <summary>
        /// 获取最新文章
        /// </summary>
        /// <param name="count">数量限制</param>
        /// <returns>最新文章列表</returns>
        Task<IEnumerable<Article>> GetLatestArticlesAsync(int count = 10);

        /// <summary>
        /// 获取热门文章
        /// </summary>
        /// <param name="count">数量限制</param>
        /// <returns>热门文章列表</returns>
        Task<IEnumerable<Article>> GetPopularArticlesAsync(int count = 10);

        /// <summary>
        /// 分页获取文章列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="keyword">搜索关键词</param>
        /// <param name="categoryId">分类ID</param>
        /// <param name="status">状态过滤</param>
        /// <param name="isSticky">是否置顶</param>
        /// <returns>分页结果</returns>
        Task<(IEnumerable<Article> Items, int TotalCount)> GetPagedAsync(
            int pageIndex, 
            int pageSize, 
            string? keyword = null, 
            long? categoryId = null,
            byte? status = null,
            bool? isSticky = null);
        
        /// <summary>
        /// 添加新文章
        /// </summary>
        /// <param name="entity">要添加的文章实体</param>
        /// <returns>添加操作任务</returns>
        Task AddAsync(Article entity);
        
        /// <summary>
        /// 更新文章信息
        /// </summary>
        /// <param name="entity">更新后的文章实体</param>
        /// <returns>更新操作任务</returns>
        Task UpdateAsync(Article entity);
        
        /// <summary>
        /// 删除文章
        /// </summary>
        /// <param name="id">文章标识符</param>
        /// <returns>删除操作任务</returns>
        Task DeleteAsync(long id);

        /// <summary>
        /// 批量删除文章
        /// </summary>
        /// <param name="ids">文章ID列表</param>
        /// <returns>删除数量</returns>
        Task<int> BatchDeleteAsync(IEnumerable<long> ids);

        /// <summary>
        /// 增加文章阅读量
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>是否更新成功</returns>
        Task<bool> IncrementViewCountAsync(long id);

        /// <summary>
        /// 增加文章点赞数
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>是否更新成功</returns>
        Task<bool> IncrementLikeCountAsync(long id);

        /// <summary>
        /// 检查文章别名是否存在
        /// </summary>
        /// <param name="slug">文章别名</param>
        /// <param name="excludeId">排除的文章ID</param>
        /// <returns>是否存在</returns>
        Task<bool> SlugExistsAsync(string slug, long? excludeId = null);

        /// <summary>
        /// 搜索文章
        /// </summary>
        /// <param name="keyword">搜索关键词</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns>搜索结果</returns>
        Task<(IEnumerable<Article> Items, int TotalCount)> SearchAsync(
            string keyword, 
            int pageIndex = 1, 
            int pageSize = 20);
    }
}
